#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;

ll x[5];

ll f1(){
    return x[4]*1000+x[3]*100+x[2]*10+x[1];
}
ll f2(){
    return x[1]*1000+x[2]*100+x[3]*10+x[4];
}


int main()
{
    IOS;
    ll n;
    cin>>n;
    ll ans=0;
    while(n!=6174){
        x[1]=n/1000;
        x[2]=(n%1000)/100;
        x[3]=(n%100)/10;
        x[4]=n%10;
    sort(x+1,x+5);
    ll maxn=f1();
    ll minn=f2();
    n=maxn-minn;
    ans++;
    }
    cout<<ans<<endl;
    getchar();
    getchar();
    return 0;
}
